﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IWMAG.Core.Messaging;

namespace IWMAG.Core.Objects {
    public abstract class GameObject {
        internal int Id;
        //protected ScriptContext Script = null;
        protected float LifeTime;
        protected Level Level;
        public bool Enabled = true;

        ~GameObject() {
            //Destroy();
        }

        public virtual void Load(int id, Level level) {
            Id = id;
            Level = level;
            RaiseEvent(EventType.OnLoad);
        }

        public virtual void Destroy() {
            RaiseEvent(EventType.OnDestroy);
        }

        public virtual void Update(float elapsed) {
            LifeTime += elapsed;
            RaiseEvent(EventType.OnUpdate);
        }

        public void RaiseEvent(EventType type) {
            if (type != EventType.OnUpdate && type != EventType.OnDraw) {
                Level.Messages.SendMessage(new Message(type, Id));
            }
            /*if (Script != null) {
                //Script.RaiseEvent(type, this);
            }*/
        }

        public virtual void ReceiveMessage(Message msg) {
        }
    }
}
